<template>
  <div id="save">
    <h2>添加用户</h2>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="登录名" prop="userName">
        <el-input v-model="ruleForm.userName"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="ruleForm.password" show-password></el-input>
      </el-form-item>
      <el-form-item label="真实姓名" prop="realName">
        <el-input v-model="ruleForm.realName"></el-input>
      </el-form-item>
      <el-form-item label="用户类别">
        <el-select v-model="ruleForm.useType" clearable placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="医生职称ID" prop="docTitleID">
        <el-input v-model="ruleForm.docTitleID" type="number"></el-input>
      </el-form-item>
      <el-form-item label="是否参与排班">
        <el-select v-model="ruleForm.isScheduling" clearable placeholder="请选择">
         <el-option label="是" value='是'></el-option>
         <el-option label="否" value='否'></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所在科室ID" prop="deptID">
        <el-input v-model="ruleForm.deptID" type="number"></el-input>
      </el-form-item>
      <el-form-item label="挂号级别ID" prop="registLeID">
        <el-input v-model="ruleForm.registLeID" type="number"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="addUser()" >添加</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import user from '@/api/his/user'
  export default {
    data() {
      return {
        ruleForm: {

        },
        rules: {
          userName: [{
              required: true,
              message: '请输入登录名',
              trigger: 'blur'
            },
            {
              min: 1,
              max: 10,
              message: '长度在 1 到 10 个字符',
              trigger: 'blur'
            }
          ],
          password: [{
              required: true,
              message: '请输入密码',
              trigger: 'blur'
            },
            {
              min: 5,
              max: 15,
              message: '长度在 5 到 15 个字符',
              trigger: 'blur'
            }
          ],
          realName: [{
              required: true,
              message: '请输入真实姓名',
              trigger: 'blur'
            },
            {
              min: 2,
              max: 10,
              message: '长度在 2 到 10 个字符',
              trigger: 'blur'
            }
          ],
          deptID:{
              required: true,
              message: '请输入所在科室ID',
              trigger: 'blur'
            },
        },
        options: [{
          value: 1,
          label: '医院管理员'
        }, {
          value: 2,
          label: '挂号收费员'
        }],
      };
    },
    methods: {
      addUser(){
        this.$refs.ruleForm.validate(async valid => {
          if(!valid){
            this.$message.warning('请正确填写表单必填项');
            return
          }else{
            user.addUser(this.ruleForm).then((res) => {
              if(res.data.code == 20000){
                this.$message.success("添加成功")
                this.$router.push({path:'/user'})
              }else{
                this.$message.error("添加失败")
              }
            }).catch((err) => {
              console.log(err)
            });
          }
        })
      }
    }
  }
</script>

<style>

</style>
